﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Base;
using System.Windows.Media;
using System.Windows;

namespace ViewModel
{
    public class MainWindowViewModel:INotifyPropertyChangedBase
    {
        public MainWindowViewModel()
        {
            cts= new CancellationTokenSource(); 
            Task.Run(() =>
            {
                UpdateData();
            },cts.Token);
        }

        private void UpdateData()
        {
            while (!cts.IsCancellationRequested)
            {
                SystemTime = DateTime.Now.ToString("G");
                resetEvent.WaitOne();
                SetLight_1((Light)Light1);
                SetLight_2((Light)Light2);
                SetLight_3((Light)Light3);
                Thread.Sleep(1000);
                Light1++;
                if (Light1 >3) { Light1 = 1; }
                Light2 = Light3 = Light1;
            }
        }

        private void SetLight_1(Light light)//1
        {
            switch (light)
            {
                case Light.Red:
                    YellowLight_1 = Visibility.Hidden;
                    GreenLight_1 = Visibility.Hidden;
                    RedLight_1 = Visibility.Visible;
                    break;
                case Light.Green:
                    YellowLight_1 = Visibility.Hidden;
                    GreenLight_1 = Visibility.Visible;
                    RedLight_1 = Visibility.Hidden;
                    break;
                case Light.Yellow:
                    YellowLight_1 = Visibility.Visible;
                    GreenLight_1 = Visibility.Hidden;
                    RedLight_1 = Visibility.Hidden;
                    break;
                default:
                    YellowLight_1 = Visibility.Hidden;
                    GreenLight_1 = Visibility.Hidden;
                    RedLight_1 = Visibility.Visible;
                    break;
            }

        }
        private void SetLight_2(Light light)//1
        {
            switch (light)
            {
                case Light.Red:
                    YellowLight_2 = Visibility.Hidden;
                    GreenLight_2 = Visibility.Hidden;
                    RedLight_2 = Visibility.Visible;
                    break;
                case Light.Green:
                    YellowLight_2 = Visibility.Hidden;
                    GreenLight_2 = Visibility.Visible;
                    RedLight_2 = Visibility.Hidden;
                    break;
                case Light.Yellow:
                    YellowLight_2 = Visibility.Visible;
                    GreenLight_2 = Visibility.Hidden;
                    RedLight_2 = Visibility.Hidden;
                    break;
                default:
                    YellowLight_2 = Visibility.Hidden;
                    GreenLight_2 = Visibility.Hidden;
                    RedLight_2 = Visibility.Visible;
                    break;
            }

        }
        private void SetLight_3(Light light)//1
        {
            switch (light)
            {
                case Light.Red:
                    YellowLight_3 = Visibility.Hidden;
                    GreenLight_3 = Visibility.Hidden;
                    RedLight_3 = Visibility.Visible;
                    break;
                case Light.Green:
                    YellowLight_3 = Visibility.Hidden;
                    GreenLight_3 = Visibility.Visible;
                    RedLight_3 = Visibility.Hidden;
                    break;
                case Light.Yellow:
                    YellowLight_3 = Visibility.Visible;
                    GreenLight_3 = Visibility.Hidden;
                    RedLight_3 = Visibility.Hidden;
                    break;
                default:
                    YellowLight_3 = Visibility.Hidden;
                    GreenLight_3 = Visibility.Hidden;
                    RedLight_3 = Visibility.Visible;
                    break;
            }

        }
        public int Light1 { get; set; } = 1;
        public int Light2 { get; set; } = 1;
        public int Light3 { get; set; } = 1;
        public void DelayMethod()
        {
             Task.Delay(1000); // 延时1秒
        }
        private CancellationTokenSource cts;//线程取消
        private ManualResetEvent resetEvent= new ManualResetEvent(true);   //线程暂停、继续
        private string systemTime=DateTime.Now.ToString("G");

        public string SystemTime
        {
            get { return systemTime; }
            set 
            { 
                systemTime = value;
                OnPropertyChanged("SystemTime");
            }
        }

        private Brush door1= Brushes.Red;

        public Brush Door1
        {
            get { return door1; }
            set {
                door1 = value;
                OnPropertyChanged("Door1");
            }
        }

        private Brush door2 = Brushes.Red;

        public Brush Door2
        {
            get { return door2; }
            set
            {
                door2 = value;
                OnPropertyChanged("Door2");
            }
        }

        private Brush door3 = Brushes.Red;

        public Brush Door3
        {
            get { return door3; }
            set
            {
                door3 = value;
                OnPropertyChanged("Door3");
            }
        }

        private Visibility yellowLight_1=Visibility.Hidden;
        /// <summary>
        /// 1#库黄灯
        /// </summary>
        public Visibility YellowLight_1
        {
            get { return yellowLight_1; }
            set {
                yellowLight_1 = value;

                OnPropertyChanged("YellowLight_1");
            }
        }
        private Visibility yellowLight_2 = Visibility.Hidden;
        /// <summary>
        /// 2#库黄灯
        /// </summary>
        public Visibility YellowLight_2
        {
            get { return yellowLight_2; }
            set
            {
                yellowLight_2 = value;

                OnPropertyChanged("YellowLight_2");
            }
        }

        private Visibility yellowLight_3 = Visibility.Hidden;
        /// <summary>
        /// 3#库黄灯
        /// </summary>
        public Visibility YellowLight_3
        {
            get { return yellowLight_3; }
            set
            {
                yellowLight_3 = value;

                OnPropertyChanged("YellowLight_3");
            }
        }
        private Visibility greenLight_1 = Visibility.Hidden;
        /// <summary>
        /// 1#库绿灯
        /// </summary>
        public Visibility GreenLight_1
        {
            get { return greenLight_1; }
            set
            {
                greenLight_1 = value;

                OnPropertyChanged("GreenLight_1");
            }
        }
        private Visibility greenLight_2 = Visibility.Hidden;
        /// <summary>
        /// 2#库绿灯
        /// </summary>
        public Visibility GreenLight_2
        {
            get { return greenLight_2; }
            set
            {
                greenLight_2 = value;

                OnPropertyChanged("GreenLight_2");
            }
        }

        private Visibility greenLight_3 = Visibility.Hidden;
        /// <summary>
        /// 3#库绿灯
        /// </summary>
        public Visibility GreenLight_3
        {
            get { return greenLight_3; }
            set
            {
                greenLight_3 = value;

                OnPropertyChanged("GreenLight_3");
            }
        }

        private Visibility redLight_1 = Visibility.Visible;
        /// <summary>
        /// 1#库红灯
        /// </summary>
        public Visibility RedLight_1
        {
            get { return redLight_1; }
            set
            {
                redLight_1 = value;

                OnPropertyChanged("RedLight_1");
            }
        }
        private Visibility redLight_2 = Visibility.Visible;
        /// <summary>
        /// 2#库红灯
        /// </summary>
        public Visibility RedLight_2
        {
            get { return redLight_2; }
            set
            {
                redLight_2 = value;

                OnPropertyChanged("RedLight_2");
            }
        }

        private Visibility redLight_3 = Visibility.Visible;
        /// <summary>
        /// 3#库红灯
        /// </summary>
        public Visibility RedLight_3
        {
            get { return redLight_3; }
            set
            {
                redLight_3 = value;

                OnPropertyChanged("RedLight_3");
            }
        }



    }

    public enum Light 
    {
    Red=1,
    Green=2,
    Yellow=3
    }
}
